<template>
    <transition name="slide-fade">
      <div v-show="visible" :class="['drawer',{'drawer-open':visible, 'drawer-open-right':placement == 'right'}]" >
        <div class="drawer-mask" style="left: -17px; width: calc(100% + 17px);" @click="handleClose"></div>
        <div class="drawer-wrapper" :style="{width:width+'px'}">
          <div class="drawer-title">
            <slot name="header">{{title}}</slot>
            <el-button type="text" icon="el-icon-close" class="close" @click="handleClose"></el-button>
          </div>
          <div class="drawer-content">
            <slot></slot>
          </div>
          <div class="drawer-footer" v-if="$slots.footer">
            <slot name="footer"></slot>
          </div>
        </div>
      </div>
    </transition>
</template>

<script>
  export default {
    props:{
      title:{
        type:String,
        default:""
      },
      placement:{
        type:String,
        default:"right"
      },
      visible:{
        type:Boolean,
        default:false
      },
      width:{
        type:Number,
        default:296
      }
    },
    methods:{
      handleClose(){
        this.$emit("update:visible",false)
        this.$emit("close",true)
      }
    }
  }
</script>

<style scoped>
.drawer{
}
.drawer-open{
  width:100%;
  height:100%;
}
.drawer > *{
  transition: transform 0.3s cubic-bezier(0.9, 0, 0.3, 0.7) 0s, -webkit-transform 0.3s cubic-bezier(0.9, 0, 0.3, 0.7) 0s;
}
.drawer-open-right{
  height:100%;
}
.drawer-open .drawer-mask{
  position: fixed;
  left:0;
  top:0;
  z-index: 1000;
  background-color: #555;
  opacity: 0.3;
  width:100%;
  height: 100%;
}
.drawer-wrapper{
  position: fixed;
  top:0;
  z-index: 1010;
  width:0%;
  background-color: #fff;
  box-shadow: rgba(0, 0, 0, 0.15) -2px 0px 8px
}
.drawer-open-right .drawer-wrapper{
  right: 0px;
  height:100%;
  transition: width 1s ease 0s;
}
.drawer-content{
  padding:20px 20px 70px 20px;
}
  .drawer-title{
    position: relative;
    padding:15px;
    border-bottom:1px solid #e7e7e7;
    font-size:16px;
    line-height: 20px;
    text-align: left;
    color:#555;
  }
  .drawer-title .close{
    position: absolute;
    right:10px;
    top:10px;
    font-size:24px;
    padding:0;
  }
  .drawer-footer{
    position: absolute;
    bottom:0;
    left:0;
    padding:15px;
    border-top:1px solid #e7e7e7;
    font-size:16px;
    text-align: left;
    color:#555;
  }
</style>